/*******************************************************************************
 * Copyright (c) 2001, 2002 Boris Pruessmann and others. All rights reserved.
 * This program and the accompanying materials are made available under the
 * terms of the Common Public License v0.5 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors: Boris Pruessmann - Initial implementation.
 ******************************************************************************/
package net.sourceforge.perforce.ui.dialogs;

import net.sourceforge.perforce.core.resources.IChangelist;
import net.sourceforge.perforce.core.resources.IP4File;
import net.sourceforge.perforce.ui.internal.Policy;

import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;

/**
 * @version $Revision: 488 $
 * @author <a href="mailto:bpruessmann@users.sourceforge.net">Boris
 *         Pruessmann</a>
 */
public class DescribeChangelistDialog extends AbstractChangeSpecDialog {

  /** Stores the changelist to describe. */
  private IChangelist changelist;

  /**
   * Constructor for DescribeChangelistDialog.
   * 
   * @param shell the parent shell.
   * @param aChangelist the changelist to describe.
   * 
   * @see AbstractChangeSpecDialog#AbstractChangeSpecDialog(Shell)
   */
  public DescribeChangelistDialog(Shell shell, IChangelist aChangelist) {
    super(shell);
    changelist = aChangelist;
  }

  @Override
  protected Text createDescriptionTextControl(Composite composite, int style) {
    return super.createDescriptionTextControl(composite, style | SWT.READ_ONLY);
  }

  @Override
  protected Table createFileTableControl(Composite parent, int style) {
    return super.createFileTableControl(parent, style & ~SWT.CHECK);
  }

  @Override
  String getChangelist() {
    int id = changelist.getId().intValue();
    return (id == IChangelist.DEFAULT.intValue()) ? "Default" : changelist.getId().toString();
  }

  @Override
  String getClientName() {
    return changelist.getClientName();
  }

  @Override
  String getDate() {
    // TODO:
    return changelist.getDate().toString();
  }

  @Override
  String getDescription() {
    return changelist.getDescription();
  }

  @Override
  String[] getFiles() {
    IP4File[] files = changelist.getFiles();
    String[] result = new String[files.length];
    for (int i = 0; i < result.length; i++) {
      result[i] = files[i].getDepotFilename();
    }
    return result;
  }

  @Override
  String getStatus() {
    return changelist.getStatus();
  }

  @Override
  String getTitle() {
    return Policy.bind("ChangeSpecDialog.dialogTitleReadOnly"); // NON-NLS-1$
  }

  @Override
  String getUserName() {
    return changelist.getUserName();
  }

  @Override
  protected void createTableButtonBar(Composite composite, TableViewer viewer) {
  }

  @Override
  protected String[] getJobs() {
    return new String[0];
  }
}
